home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
4.1
/
Eyeball.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
4KB
|
135 lines
" NAME Eyeball
AUTHOR Bernard Horan <bernard@is.morgan.com>
CONTRIBUTOR Bernard Horan <bernard@is.morgan.com>
FUNCTION Eyeballs follow your cursor
ST-VERSIONS 4.1
PREREQUISITES
CONFLICTS
DISTRIBUTION global
VERSION 2.0
DATE March 1993
SUMMARY
I hacked a 4.1 version of Eyeball.st (which Trevor wrote for version 2.2!!)
-- though I had to change it a bit. It's a good example of the use of
OpaqueImages and various palette messages. I'm still not happy with the
animation, as the background can get screwed if you resize the window.
bern"
'obligatory string'!
VisualPart subclass: #EyeballView
instanceVariableNames: 'pupilPosition pupilDiameter eyeImage pupilImage pupilProcess '
classVariableNames: ''
poolDictionaries: ''
category: 'Eyeball'!
!EyeballView methodsFor: 'initialize-release'!
release
pupilProcess isNil ifFalse:[pupilProcess terminate; release].
super release!
setDiameter: aDiameter
pupilDiameter := aDiameter.
self makePupilImage.
self startPupilProcess! !
!EyeballView methodsFor: 'displaying'!
displayOn: aGraphicsContext
eyeImage displayOn: aGraphicsContext.! !
!EyeballView methodsFor: 'bounds accessing'!
bounds: newBounds
| pixmap figure shape |
pupilPosition isNil ifTrue:[pupilPosition := newBounds center].
pixmap := Pixmap extent: newBounds extent.
(pixmap graphicsContext) displayRectangle: newBounds; paint: ColorValue white;
displayWedgeBoundedBy: newBounds
startAngle: 0
sweepAngle: 360.
figure := pixmap asImage convertToPalette: MappedPalette blackWhite.
shape := figure copy palette: CoveragePalette monoMaskPalette.
eyeImage := OpaqueImage figure: figure shape: shape.
^super bounds: newBounds!
preferredBounds
"Answer the Screen's bounding box.
Views are expected to be Wrapped by a BoundedWrapper."
^Screen default bounds! !
!EyeballView methodsFor: 'private'!
makePupilImage
| pixmap figure shape aRectangle |
aRectangle := 0 @ 0 extent: pupilDiameter asPoint.
pixmap := Pixmap extent: aRectangle extent.
pixmap graphicsContext
displayWedgeBoundedBy: aRectangle
startAngle: 0
sweepAngle: 360.
figure := pixmap asImage convertToPalette: MappedPalette whiteBlack.
shape := figure copy palette: CoveragePalette monoMaskPalette.
pupilImage := OpaqueImage figure: figure shape: shape!
startPupilProcess
| delay |
delay := Delay forMilliseconds: 250.
pupilProcess := [pupilImage
follow: [pupilPosition - (pupilDiameter asPoint //2)]
while:
[delay wait.
self updatePupil.
true]
on: self graphicsContext ] newProcess.
pupilProcess resume!
updatePupil
"Update the receiver's pupil, if necessary. Answer true if
a change was made, otherwise false."
| newP diff sign cursorPoint |
cursorPoint := self globalPointToLocal: (InputSensor cursorPoint translatedBy: self topComponent globalOrigin negated).
diff := cursorPoint - self bounds center // 5.
sign := diff x sign @ diff y sign.
newP := self bounds center + ((diff abs min: (self bounds width // 3) asPoint)
* sign).
newP = pupilPosition ifFalse: [pupilPosition := newP]! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
EyeballView class
instanceVariableNames: ''!
!EyeballView class methodsFor: 'instance creation'!
diameter: anInteger
^self new setDiameter: anInteger! !
!EyeballView class methodsFor: 'examples'!
example1
"EyeballView example1"
| window view |
window := ScheduledWindow new.
window label: 'Eyeball'.
view := self diameter: 50.
window component: view.
window open!
example2
"EyeballView example2"
| window comp |
window := ScheduledWindow new.
window label: 'Eyeballs'.
comp := CompositePart new.
comp add: (self diameter: 50) in: (0@0 extent: 0.5@1).
comp add: (self diameter: 50) in: (0.5 @ 0 corner: 1@1).
window component: comp.
window open! !